﻿using Blazui.Component;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Project13776616780_01.Model;
using Project13776616780_01.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Project13776616780_01.Pages.Adv
{
    public partial class Create
    {
        private BInput<string> editor;
        private BForm form;
        [Inject]
        private DocsDbContext dbContext { get; set; }

        private async Task CreateAsync()
        {
            if (!form.IsValid())
            {
                return;
            }
            var model = form.GetValue<AdvModel.CreateModel>();
            dbContext.Add(new Model.Adv()
            {
                Url = model.Url,
                Image = model.Image[0].Url
            });
            await dbContext.SaveChangesAsync();
            await CloseAsync();
        }
    }
}
